package org.tobuy.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.tobuy.vo.*;
import org.tobuy.factory.*;

public class AdminLogin extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String path = "admin.jsp";
		String admin_name = (String) request.getParameter("admin_name");
		String admin_pass = (String) request.getParameter("admin_pass");
		
		String info = "Admin login failed, please try again!";
		if(admin_name.equals("admin")&&admin_pass.equals("admin")){
			info = "Welcome back, administrator!";
			
			HttpSession session = request.getSession();
			session.setAttribute("login", "true");
			
		}
		
		request.setAttribute("info", info);
		request.getRequestDispatcher(path).forward(request, response);

	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doGet(request, response);
	}

}
